package com.personal.modules.sys.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.personal.common.bean.PageUtils;
import com.personal.common.bean.ResultMsg;
import com.personal.common.util.Query;
import com.personal.modules.sys.entity.TSysRoleEntity;
import com.personal.modules.sys.service.TSysRoleService;


/**
 * 角色
 * 
 * @author liuyuzhu
 * @email liuyuzhu.1314@gmail.com
 * @date 2017-10-09 16:34:03
 */
@RestController
@RequestMapping("tsysrole")
public class TSysRoleController {
	@Autowired
	private TSysRoleService tSysRoleService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("tsysrole:list")
	public ResultMsg list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<TSysRoleEntity> tSysRoleList = tSysRoleService.queryList(query);
		int total = tSysRoleService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(tSysRoleList, total, query.getLimit(), query.getPage());
		
		return new ResultMsg(pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{roleId}")
	@RequiresPermissions("tsysrole:info")
	public ResultMsg info(@PathVariable("roleId") Long roleId){
		TSysRoleEntity tSysRole = tSysRoleService.queryObject(roleId);
		
		return new ResultMsg(tSysRole);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("tsysrole:save")
	public ResultMsg save(@RequestBody TSysRoleEntity tSysRole){
		tSysRoleService.save(tSysRole);
		
		return new ResultMsg();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("tsysrole:update")
	public ResultMsg update(@RequestBody TSysRoleEntity tSysRole){
		tSysRoleService.update(tSysRole);
		
		return new ResultMsg();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("tsysrole:delete")
	public ResultMsg delete(@RequestBody Long[] roleIds){
		tSysRoleService.deleteBatch(roleIds);
		
		return new ResultMsg();
	}
	
}
